package com.youngwang.service.impl;

import com.youngwang.dao.UserDao;
import com.youngwang.entity.UserEntity;
import com.youngwang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author youngwang
 *         Date: 2016/9/20
 */

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserEntity login(@NotNull String name, @NotNull String phone) {
        List<UserEntity> userEntities = userDao.findByNameAndPhoneOrderByIdDesc(name, phone);
        if (CollectionUtils.isEmpty(userEntities)) {
            return null;
        }
        return userEntities.get(0);
    }
}
